package cn.gavin.web.controller;

import cn.gavin.domain.SystemDictionary;
import cn.gavin.qo.QueryObject;
import cn.gavin.service.ISystemDictionaryService;
import cn.gavin.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {
    @Autowired
    private ISystemDictionaryService systemDictionaryService;

    @RequiredPermission(name = "字典目录页面",expression = "systemDictionary:list")
    @RequestMapping("/list")
    public String list(Model model, QueryObject qo){
        model.addAttribute("pageInfo",systemDictionaryService.query(qo));
        return "systemDictionary/list";
    }

    @RequiredPermission(name = "字典目录删除",expression = "systemDictionary:delete")
    @RequestMapping("/delete")
    public String delete(Long id){
        if (id != null) {
            systemDictionaryService.deleteById(id);
        }
        return "redirect:/systemDictionary/list";
    }

/*
    @RequestMapping("/input")
    public String input(Long id,Model model){
        if (id != null) {
            SystemDictionary systemDictionary = systemDictionaryService.findById(id);
            model.addAttribute("systemDictionary",systemDictionary);
        }
        return "systemDictionary/input";
    }
*/

    @RequiredPermission(name = "字典目录新增/编辑",expression = "systemDictionary:save")
    @RequestMapping("/save")
    public String save(SystemDictionary systemDictionary){
        if (systemDictionary.getId() != null) {
            systemDictionaryService.update(systemDictionary);
        }else {
            systemDictionaryService.insert(systemDictionary);
        }
        return "redirect:/systemDictionary/list";
    }
}
